/**
 * Author: luoqi
 * Created Date: 2025-10-14 00:18:41
 * Last Modified: 2025-11-26 23:38:55
 * Modified By: luoqi at <**@****>
 * Copyright (c) 2025 <*****>
 * Description:
 */

#pragma once

#include <cstdint>
#include <utils/log.hpp>
#include <hw/canport.h>
#include <hw/powerflow.h>
#include <Eigen/Dense>

class XBot {
public:
    enum EnaState {
        DISABLE = 0,
        ENABLE = 1,
    };


public:
    XBot();
    ~XBot();

public:
    CanPort canfd{"can0", 1000000, CanPort::CANFD, 5000000};
    PowerFlow joints;
    bool dbg_canfd = false;

public:
    int start();
    
    int stop();

    int ena(EnaState state);

    int config();

private:
    bool running_ = false;

    std::thread thr_canfd_recv_;
    void task_canfd_recv_();

    std::thread thr_xbot_task_;
    void task_xbot_();
};

class XBotObj {
public:
    static XBot &obj()
    {
        static XBot xbot;
        return xbot;
    }
private:
    XBotObj() = default;
    ~XBotObj() = default;
    XBotObj(const XBotObj &) = delete;
    XBotObj &operator=(const XBotObj &) = delete;
};
